package com.comdo.newup_loan.module.setting;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.comdo.newup_loan.R;
import com.comdo.newup_loan.base.BaseActivity;
import com.comdo.newup_loan.comom.Config;
import com.comdo.newup_loan.util.StringUtils;
import com.comdo.newup_loan.util.TitleMenuUtil;

import butterknife.BindView;

/**
 * Created by liyuan on 2017/11/9.
 */

public class ValidatePassActivity extends BaseActivity<ValidatePassPresenter> implements ValidatePassContract.View {
    @BindView(R.id.ed_pass)
    EditText mPassEdText;
    @BindView(R.id.btn_submit)
    Button mSubmitBtn;

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.activity_validate_pass;
    }

    @Override
    protected void init() {
        super.init();
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        new TitleMenuUtil(ValidatePassActivity.this, "修改密码", false);
        mSubmitBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(StringUtils.isNull(mPassEdText.getText().toString())){
                    showToast("请输入原密码!");
                    return;
                }
                mPresenter.validate(Config.loginInfo.getUserId(), StringUtils.Md5(mPassEdText.getText().toString()));
            }
        });
    }
    @Override
    public void validate(String result) {
        showToast(result);
        Intent intent=new Intent(ValidatePassActivity.this,MofityPassActivity.class);
        startActivity(intent);
        ValidatePassActivity.this.finish();
    }

    @Override
    public void Fail(String failMessage) {
        showToast(failMessage);
    }

    @Override
    public ValidatePassPresenter getmPresenter() {
        return new ValidatePassPresenter();
    }

    @Override
    public void presenterSetView() {
        if (mPresenter != null)
            mPresenter.setView(this);
    }
}
